// JmeshclientCtl.cpp : Implementation of the CJmeshclientCtrl ActiveX Control class.

#include "stdafx.h"
#include "jmeshclient.h"
#include "JmeshclientCtl.h"
#include "JmeshclientPpg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CLoginDlg* g_pdlgLogin;
extern CMainDlg* g_pdlgMain;


IMPLEMENT_DYNCREATE(CJmeshclientCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CJmeshclientCtrl, COleControl)
	//{{AFX_MSG_MAP(CJmeshclientCtrl)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CJmeshclientCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CJmeshclientCtrl)
	// NOTE - ClassWizard will add and remove dispatch map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CJmeshclientCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CJmeshclientCtrl, COleControl)
	//{{AFX_EVENT_MAP(CJmeshclientCtrl)
	// NOTE - ClassWizard will add and remove event map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CJmeshclientCtrl, 1)
	PROPPAGEID(CJmeshclientPropPage::guid)
END_PROPPAGEIDS(CJmeshclientCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CJmeshclientCtrl, "JMESHCLIENT.JmeshclientCtrl.1",
	0xa8aea3fc, 0x4070, 0x4176, 0xbd, 0xb4, 0xc1, 0x58, 0xc4, 0x62, 0x3c, 0xe1)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CJmeshclientCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DJmeshclient =
		{ 0xec6513b, 0xf1cd, 0x42c4, { 0x92, 0x4c, 0x76, 0x38, 0xa6, 0x12, 0x5d, 0x3 } };
const IID BASED_CODE IID_DJmeshclientEvents =
		{ 0x53466d03, 0x46ad, 0x4758, { 0x93, 0xc0, 0x39, 0x67, 0x44, 0x12, 0x61, 0x2 } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwJmeshclientOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CJmeshclientCtrl, IDS_JMESHCLIENT, _dwJmeshclientOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CJmeshclientCtrl::CJmeshclientCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CJmeshclientCtrl

BOOL CJmeshclientCtrl::CJmeshclientCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_JMESHCLIENT,
			IDB_JMESHCLIENT,
			afxRegApartmentThreading,
			_dwJmeshclientOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CJmeshclientCtrl::CJmeshclientCtrl - Constructor

CJmeshclientCtrl::CJmeshclientCtrl()
{
	InitializeIIDs(&IID_DJmeshclient, &IID_DJmeshclientEvents);

	// TODO: Initialize your control's instance data here.

	//SetInitialSize( 1366 + 90, 768 + 56 ); 
}


/////////////////////////////////////////////////////////////////////////////
// CJmeshclientCtrl::~CJmeshclientCtrl - Destructor

CJmeshclientCtrl::~CJmeshclientCtrl()
{
	// TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CJmeshclientCtrl::OnDraw - Drawing function

void CJmeshclientCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
//	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
//	pdc->Ellipse(rcBounds);
}


/////////////////////////////////////////////////////////////////////////////
// CJmeshclientCtrl::DoPropExchange - Persistence support

void CJmeshclientCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CJmeshclientCtrl::OnResetState - Reset control to default state

void CJmeshclientCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CJmeshclientCtrl::AboutBox - Display an "About" box to the user

void CJmeshclientCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_JMESHCLIENT);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CJmeshclientCtrl message handlers
int CJmeshclientCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (COleControl::OnCreate(lpCreateStruct) == -1)
		return -1;

	if ( NULL == g_pdlgLogin ) 
	{
		g_pdlgLogin = new CLoginDlg(this);
		g_pdlgLogin->Create( IDD_DIALOG_LOGIN, this );
		//g_pdlgLogin->CenterWindow();
		g_pdlgLogin->ShowWindow( SW_SHOW );
	}

	if ( NULL == g_pdlgMain ) 
	{
		g_pdlgMain = new CMainDlg(this);
		g_pdlgMain->Create( IDD_DIALOG_MAIN, this );
		//g_pdlgMain->CenterWindow();
		g_pdlgMain->ShowWindow( SW_HIDE );
	}

	return 0;
}
